package com.hutiao.snowhb.actions.huodong;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.beans.factory.annotation.Autowired;

import com.hutiao.snowhb.dao.BaseDao;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 光影园林报名
 * @author subob
 *
 */
@Namespace("/huodong")
@Results({ 
	@Result(name="success", location="guangyingyuanlin.jsp"),
	@Result(name="input", location="guangyingyuanlin.jsp")})
public class GuangyingyuanlinAction extends ActionSupport {

	private static final long serialVersionUID = 6133186027454224378L;

	private static Logger logger = Logger.getLogger(GuangyingyuanlinAction.class);

	@Autowired
	private BaseDao baseDao;

	@JSON(serialize=false)
	public BaseDao getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	
	private YuanlinFormBean bean;

	@JSON(serialize=false)
	public YuanlinFormBean getBean() {
		return bean;
	}

	public void setBean(YuanlinFormBean bean) {
		this.bean = bean;
	}
	
	private String openId;
	
	@JSON(serialize=false)
	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}
	
	private String result;
	
	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	@Action(value="guangyingyuanlin")
	public String execute() throws Exception {
		
		return SUCCESS;
	}
	
	
	@Action(value="guangyingyuanlin_save",results = { @Result(type = "json") })
	public String save() throws Exception {
		
		if (this.bean == null) {
			this.result = "请填写姓名";
			return SUCCESS;
		}
		
		if (this.bean.getName() == null || this.bean.getName().equals("")) {
			this.result = "请填写姓名";
			return SUCCESS;
		}
		
		if (this.bean.getPhone() == null || this.bean.getPhone().equals("")) {
			this.result = "请填写手机号";
			return SUCCESS;
		}
		
		
		String sql = "insert into hd_guangyingyuanlin(openId,scene,`name`,age,gender,phone,city,career,createTime,updateTime) "
				+ "values('"+this.openId+"','"+this.bean.getScene()+"','"+this.bean.getName()+"','"+this.bean.getAge()+"','"+this.bean.getGender()+"','"+this.bean.getPhone()+"','"+this.bean.getCity()+"','"+this.bean.getCareer()+"',now(),now());";
		
		try {
			this.baseDao.execute(sql);
			this.result = "您已成功报名光影园林活动";
		} catch (Exception e) {
			logger.error("Exception", e);
			
			return ERROR;
		}
		
		
		return SUCCESS;
	}
	
}

class YuanlinFormBean {
	
	private String scene;
	
	private String name;
	
	private int age;
	
	private String gender;
	
	private String phone;
	
	private String city;
	
	private String career;

	public String getScene() {
		return scene;
	}

	public void setScene(String scene) {
		this.scene = scene;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getCareer() {
		return career;
	}

	public void setCareer(String career) {
		this.career = career;
	}
	
	
}
